package com.qf.config;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * author:z
 * time:2021/12/17 16:24
 * description:
 */
@Configuration
public class RabbitMqConfig {

    //队列
    //@Bean 指定名称
    @Bean("queue1")
    public Queue getQueue1(){
        return new Queue("boot-queue1");
    }

    //队列
    @Bean("queue2")
    public Queue getQueue2(){
        return new Queue("boot-queue2");
    }

//    //交换机 广播模式
//    @Bean
//    public FanoutExchange getExchange(){
//        return new FanoutExchange("boot-exchange",true,false);
//    }

    //交换机 广播模式
    @Bean
    public DirectExchange getExchange(){
        return new DirectExchange("boot-exchange",true,false);
    }


    //绑定
    //只需要绑定一个的时候不需要加Qualifier
//    @Bean
//    public Binding getBinding(Queue queue,FanoutExchange exchange){
//        return BindingBuilder.bind(queue).to(exchange);
//    }

    //广播模式
//    @Bean
//    public Binding getBinding1(@Qualifier("queue1") Queue queue,FanoutExchange exchange){
//        return BindingBuilder.bind(queue).to(exchange);
//    }
//
//    @Bean
//    public Binding getBinding2(@Qualifier("queue2") Queue queue,FanoutExchange exchange){
//        return BindingBuilder.bind(queue).to(exchange);
//    }

    //路由模式 需要加with 添加绑定路由规则
    //@Qualifier 指定值
    @Bean
    public Binding getBinding1(@Qualifier("queue1") Queue queue,DirectExchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("dog");
    }

    @Bean
    public Binding getBinding2(@Qualifier("queue2") Queue queue,DirectExchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("pig");
    }

}
